﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.WebNemo.Business.Groups;
using System.Web.UI.WebControls;

namespace blackhouse.WebNemo.Web.Controls {
	public class ManyDisplayRecordValue : DisplayRecordValue {

		#region Fields

		private GroupRecord[] refRecords;

		#endregion

		#region Properties

		public GroupRecord[] RefRecords {
			get {
				if (refRecords == null)
					refRecords = this.record.GetRecords(this.column.ColumnName);
				return refRecords;
			}
		}

		#endregion

		#region Methods

		protected override void PopulateControl() {
			this.Controls.Clear();
			foreach (GroupRecord refRecord in RefRecords) {
				HyperLink displayControl = new HyperLink();
				this.Controls.Add(displayControl);
				this.Controls.Add(new Literal() { Text = "<br />" });
				displayControl.Text = refRecord.Identyficator + "<span></span>";
				displayControl.CssClass = "record-ref";
				displayControl.ToolTip = "Pokaż cały rekord";
                NemoUrl url = NemoUrl.Get();
                url.GroupId = refRecord.BelongsToGroupId;
                url.RecordId = refRecord.RecordId;
                url.View = NemoUrlView.Preview;
                displayControl.NavigateUrl = url.GetUrl();
			}
		}

		public override bool IsEmpty() {
			return RefRecords.Length == 0; 
		}

		#endregion

	}
}